/**
 * Copyright: Copyright (c)2011
 * Company: 易宝支付(YeePay)
 */
package net.loyintean.pearlshell.logcenter.db.logger;

import net.loyintean.pearlshell.logcenter.db.LoggerDBService;
import net.loyintean.pearlshell.logcenter.model.ILogModel;
import net.loyintean.pearlshell.logcenter.model.impl.ILogFactory;

import org.apache.log4j.AppenderSkeleton;
import org.apache.log4j.spi.LoggingEvent;

/** 数据库日志生产者
 * 
 * @author：jun.lin@yeepay.com
 * @since：2015年1月17日 下午2:35:18
 * @version: */
class Appender4DB extends AppenderSkeleton {

	/** 系统名称 */
	private String systemName;

	/** dbService :数据库接口 */
	private LoggerDBService dbService;

	/** @see org.apache.log4j. AppenderSkeleton#append(LoggingEvent) */
	@Override
	protected void append(LoggingEvent event) {
		ILogModel logModel = ILogFactory.build(systemName, event);

		dbService.saveLogger(logModel);

	}

	/** @see org.apache.log4j.Appender#close() */
	@Override
	public void close() {
	}

	/** @see org.apache.log4j.Appender#requiresLayout() */
	@Override
	public boolean requiresLayout() {
		return false;
	}

	/** @param systemName
	 *            the systemName to set */
	public void setSystemName(String systemName) {
		this.systemName = systemName;
	}

	/** @param dbService
	 *            the dbService to set */
	public void setDbService(LoggerDBService dbService) {
		this.dbService = dbService;
	}
}
